package com.twu.biblioteca.events;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: cschlumb
 * Date: 21/08/2013
 * Time: 14:44
 * To change this template use File | Settings | File Templates.
 */
public class Event {

    List<Listener> listeners = new ArrayList<Listener>();


    public void addListener(Listener listener) {
        listeners.add(listener);
    }

    public int numberOfListeners() {
        return listeners.size();
    }

    public void fire() {
        for (Listener listener : listeners){
            listener.onEvent();
        }
    }

    public void removeListener(Listener listener) {
        listeners.remove(listener);
    }

    public void removeAllListeners() {
        listeners.clear();
    }
}
